package com.it.schoolbookshop_back.entities.vo;

import com.it.schoolbookshop_back.entities.po.Message;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 消息展示对象，用于前端展示
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MessageVO {
    /**
     * 消息ID
     */
    private Integer id;
    
    /**
     * 发送者ID
     */
    private Integer senderId;
    
    /**
     * 发送者用户名
     */
    private String senderName;
    
    /**
     * 接收者ID
     */
    private Integer receiverId;
    
    /**
     * 接收者用户名
     */
    private String receiverName;
    
    /**
     * 图书ID
     */
    private Integer bookId;
    
    /**
     * 图书标题
     */
    private String bookTitle;
    
    /**
     * 消息内容
     */
    private String content;
    
    /**
     * 是否已读
     */
    private Boolean isRead;
    
    /**
     * 是否为当前用户发送的消息
     */
    private Boolean isSelf;
    
    /**
     * 创建时间
     */
    private LocalDateTime createdAt;
    
    /**
     * 根据Message和其他相关信息构建MessageVO
     */
    public static MessageVO fromMessage(Message message, String senderName, String receiverName, 
                                        String bookTitle, Integer currentUserId) {
        return MessageVO.builder()
                .id(message.getId())
                .senderId(message.getSenderId())
                .senderName(senderName)
                .receiverId(message.getReceiverId())
                .receiverName(receiverName)
                .bookId(message.getBookId())
                .bookTitle(bookTitle)
                .content(message.getContent())
                .isRead(message.getIsRead())
                .isSelf(message.getSenderId().equals(currentUserId))
                .createdAt(message.getCreatedAt())
                .build();
    }
} 